﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using Quartz;
using Common.Logging;
using Quartz.Impl;
using Castle.Windsor;
using Castle.Windsor.Installer;
using DAL;

namespace ScheduleService
{
    public partial class MainService : ServiceBase
    {
        //日志记录这。
        private readonly ILog _logger;
        private static IWindsorContainer container;
        //调度器。
        private readonly IScheduler _scheduler;

        public MainService()
        {
            InitializeComponent();

            BootstrapContainer.CreateContainer();
            
            this._logger = LogManager.GetLogger(this.GetType());
            StdSchedulerFactory factory = new StdSchedulerFactory();
            this._scheduler = factory.GetScheduler();
            this._scheduler.Start();
        }

        protected override void OnStart(string[] args)
        {
            this._scheduler.Start();
            this._logger.Info("服务启动");
        }

        protected override void OnStop()
        {
            if (!this._scheduler.IsShutdown)
                this._scheduler.Shutdown();
            this._logger.Info("服务停止");
        }

        protected override void OnPause()
        {
            this._scheduler.PauseAll();
            base.OnPause();
        }

        protected override void OnContinue()
        {
            this._scheduler.ResumeAll();
            base.OnContinue();
        } 
    }
}
